<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SetObject
 *
 * @author David
 */
class SetObject {

    public function set($object, $entity, $linha2) {
        $attrs = $this->attributsEntity($object);

        foreach ($attrs as $key => $attr) {
            if ($this->existEntity($key)) {
                $newSetObject = new SetObject();
                
                // clona o objeto para perder o indice (Refatorar depois)
                $object->$key = clone $object->$key;
                
                $object->$key = $newSetObject->set($object->$key, $key, $linha2);
            } else {
                $object->$key = $linha2[strtolower("$entity.$key")];
            }
        }

        return $object;
    }

    public function attributsEntity($entity) {
        return get_class_vars(get_class($entity));
    }

    /**
     * Verifica se o dado é Entidade
     * @param object $entity
     * @return boolean
     */
    public function existEntity($entity) {
        $arquivoEntity = '../entity/' . ucfirst($entity) . ".php";
        if (file_exists($arquivoEntity)) {
            return true;
        } else {
            return false;
        }
    }

}

?>
